﻿<div ng-controller="Supplier_SupplierEditC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">钢厂基本信息管理</h1>
    </div>
    <div class="wrapper-md">
        <div class="panel panel-default">
            <div class="table-responsive">
                <form name="form" class="form-validation">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <span class="h4">钢厂基本信息管理</span>
                        </div>
                        <div class="panel-body">

                            <div class="form-group">
                                <label>名称</label>
                                <input disabled type="text" class="form-control" ng-model="data.Name">
                            </div>
                            <div class="form-group">
                                <label>品牌名称</label>
                                <input required ng-model="data.Brand" type="text" class="form-control">
                            </div>
                            <!--<div class="form-group">-->
                                <!--<label>地区 </label>-->
                                <!--<div class="input-group ">-->
                                    <!--<span class="input-group-addon">省</span>-->
                                    <!--<select required class="form-control" ng-options="x.FillName for x in districts" ng-model="selectedDistrict1"></select>-->
                                    <!--<span class="input-group-addon">市</span>-->
                                    <!--<select required class="form-control" ng-options="y.Name for y in selectedDistrict1.Children track by x.Id" ng-model="data.District" name="District">-->
                                        <!--&lt;!&ndash;<option ng-repeat="y in selectedDistrict1.Children" value="{{y.Id}}">{{y.Name}}</option>&ndash;&gt;-->
                                    <!--</select>-->
                                <!--</div>-->
                            <!--</div>-->

                            <!--<div class="form-group">-->
                                <!--<label>地址</label>-->
                                <!--<input type="text" class="form-control" ng-model="data.Address">-->
                            <!--</div>-->
                            <div class="form-group">
                                <label>联系人</label>
                                <input required type="text" class="form-control" ng-model="data.Contacts">
                            </div>
                            <div class="form-group">
                                <label>电话</label>
                                <input required type="text" class="form-control" ng-model="data.Phone" ng-pattern="/^[1][3-8]\d{9}$/">
                            </div>

                            <div class="form-group">
                                <label>备注（非必填）</label>
                                <input type="text" class="form-control" ng-model="data.Remarks">
                            </div>
                        </div>
                        <footer class="panel-footer text-right bg-light lter">
                            <button type="button" ng-disabled="form.$invalid" class="btn btn-success" ng-click="edit()">修改</button>
                            <button type="button" class="btn btn-default" ng-click="abolish()">取消</button>
                        </footer>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    angular.module('app')//非标优惠
.controller("Supplier_SupplierEditC", function ($scope, $state, $http, $stateParams) {
    console.log($stateParams.id);
    $http.get("/api/Supplier", { params: { "id": $stateParams.id } })
       .then(function (res) {
           $scope.data = res.data;
           console.log($scope.data.District);
           })
       .then(function (error) {
           if (error) {
               alert("数据获取失败");
           }
       });
    //获取地市
//    $http({
//        url: "/api/District",
//        method: "GET"
//    })
//        .then(function (res) {
//            $scope.districts = res.data;
//            for (var i = 0; i < $scope.districts.length; i++) {
//                if ($scope.districts[i].Id == $scope.data.District.Parent.Id) {
//                    $scope.selectedDistrict1 = $scope.districts[i];
//                }
//            }
//        },function (error) {
//            if (error) {
//                console.log("error");
//            }
//        });
    $scope.edit = function () {
        console.log($scope.data);
        $http.put("/api/Supplier", $scope.data)
       .then(function (res) {
           alert("编辑成功");
           $state.go("app.Supplier_List");
       },function (error) {
           alert("处理失败");

       })
        ;
    };
    //取消更改
    $scope.abolish = function(){
        $state.go("app.Supplier_List");
    }
    })

</script>